import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TreePersonModule } from './modules/tree-person/tree-person.module';
import { TreePerson } from '@/modules/tree-person/tree-person.entity';
import { AuthModule } from './modules/auth/auth.module';
import { UserModule } from './modules/user/user.module';
import { User } from './modules/user/user.entity';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { file: envFilePath } = require('../../../config/env');

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true, envFilePath: [envFilePath] }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => {
        return {
          type: 'mysql',
          host: configService.get('DB_HOST', '110.40.139.133'),
          username: configService.get('DB_USER', 'root'),
          password: configService.get('DB_PASSWORD', 'rootroot'),
          port: configService.get('DB_PORT', 3306),
          database: configService.get('DB_DATABASE', 'exam_dev'),
          charset: 'utf8mb4',
          timezone: '+08:00',
          synchronize: true,
          entities: [TreePerson, User],
        };
      },
    }),
    TreePersonModule,
    AuthModule,
    UserModule,
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}
